// src/api.js
import axios from 'axios';

const URL = 'http://back1.idcfengye.com:15173'; 

// 查询拿到比赛的名称
export const getMatches = async () => {
  try {
    const response = await axios.get(`${URL}/competition/match`);
    return response.data;
  } catch (error) {
    console.error('There was a problem fetching the matches:', error);
    throw error;
  }
};

// 根据matchIds获取比赛项目
export const getMatchProjects = async (matchIds) => {
  // 确保matchIds是一个数组
  if (!Array.isArray(matchIds)) {
    throw new TypeError('matchIds must be an array');
  }
  try {
    const matchIdsString = matchIds.join(',');
    const response = await axios.post(`${URL}/match/${matchIdsString}/projects`, { matchIds });
    return response.data;
  } catch (error) {
    console.error('Error fetching match projects:', error);
    throw error;
  }
};


